<?php
/**
 * Provides some helper functions. All helper functions are used in the theme as
 * custom template tags. Most of them are attached to action and filter hooks
 * to change Theme and WordPress related functionality.
 *
 * All functions below are attached to WordPress and dkret hooks with add_action()
 * and add_filter() call inside 'functions.php'
 *
 * When using a child theme (see http://codex.wordpress.org/Theme_Development), you can
 * override those functions (those wrapped in a function_exists() call) by defining
 * them first in your child theme's functions.php file. The child theme's functions.php
 * file is included before the parent theme's file, so the child theme functions would
 * be used.
 *
 * Alternatively remove added functions by using remove_action() or remove_filter() and attach
 * your own function.
 *
 * Action hooks should be defined and named by the order called (generated) relative to a theme element.
 * Most 'before' action hooks appear just inside of the opening XHTML element it's named after.
 * Most 'after' action hooks appear just inside of the closing XHTML element it's named after.
 *
 * For more information on hooks, see http://codex.wordpress.org/Plugin_API.
 *
 * @package dkret3
 * @since 3.6
 */

if ( ! function_exists( 'dkret_site_title' ) ) :
/**
 * Dynamic element to wrap the site title in.  If it is the home or front page, wrap
 * it in an <h1> element.  On other pages, wrap it in a <div> element.
 *
 * @since 0.1
 */
function dkret_site_title() {

	if ( $title = get_bloginfo( 'name' ) ) :
    	$tag = ( is_home() || is_front_page() ) ? 'h1' : 'div';
		$title = '<' . $tag . ' id="site-title"><a href="' . home_url() . '" title="' . $title . '" rel="home"><span>' . $title . '</span></a></' . $tag . '>';
    endif;

	echo apply_filters( 'dkret_site_title', $title );
}
endif;

if ( ! function_exists( 'dkret_site_description' ) ) :
/**
 * Dynamic element to wrap the site title in.  If it is the home or front page, wrap
 * it in an <h1> element.  On other pages, wrap it in a <div> element.
 *
 * @since 0.1
 */
function dkret_site_description() {

    if ( $desc = get_bloginfo( 'description' ) ) :
		$desc = '<div id="site-description"><span>' . $desc . '</span></div>';
    endif;

	echo apply_filters( 'dkret_site_description', $desc );
}
endif;

if ( ! function_exists( 'dkret_rss_link' ) ) :
/**
 * Function to print rss link for the top navigation #access
 *
 * @since 3.6
 */
function dkret_rss_link() {
    if ( get_dkret_option( 'rss_link' ) )
        printf( '<span class="access-rss access-link"><a href="%1$s" title="%2$s">%3$s</a></span>',
            get_bloginfo( 'rss2_url' ),
            sprintf( __( 'RSS 2.0 feed for the posts', 'dkret') ),
            sprintf( __( 'RSS', 'dkret' ) ) );
}
endif;

if ( ! function_exists( 'dkret_gallery_link' ) ) :
/**
 * Function to print gallery link for the top navigation #access
 *
 * @since 3.6
 */
function dkret_gallery_link() {
    if ( get_dkret_option('gallery_link') )
        printf( '<span class="access-gallery access-link"><a href="%1$s" title="%2$s">%3$s</a></span>',
            get_post_format_link( 'gallery' ),
            sprintf( __( 'Browse the Gallery', 'dkret' ) ),
            sprintf( __( 'Gallery', 'dkret' ) ) );
}
endif;

if ( ! function_exists( 'dkret_single_post_navigation' ) ) :
/**
 * displays a link to the previous and next post on single post pages 
 *
 * @since 3.6
 */
function dkret_single_post_navigation() {

    if ( ! is_attachment() && ! is_page() ) : ?>

        <div id="nav" class="navigation">

            <?php
                $args = array(
                    'format' => '%link',
                    'link' => '<span class="nav-previous"><span class="meta-nav">&laquo;</span> '. __('previous post', 'dkret') .'</span>',
                    'in_same_cat' => FALSE,
                    'excluded_categories' => ''
                );

                $args = apply_filters('dkret_previous_post_link_args', $args );

                previous_post_link( $args['format'], $args['link'], $args['in_same_cat'], $args['excluded_categories'] );

                $args = array (
                    'format' => '%link',
                    'link' => '<span class="nav-next">'. __('next post', 'dkret') .' <span class="meta-nav">&raquo;</span></span>',
                    'in_same_cat' => FALSE,
                    'excluded_categories' => '');
                
                $args = apply_filters( 'dkret_next_post_link_args', $args );
                next_post_link( $args['format'], $args['link'], $args['in_same_cat'], $args['excluded_categories'] );
            ?>
            
        </div>

    <?php endif;
}
endif;

if ( ! function_exists( 'dkret_post_navigation' ) ) :
/**
 * displays the posts navigation
 *
 * @since 3.6
 */
function dkret_post_navigation() { ?>

        <div id="nav-below" class="navigation">
            <?php if ( function_exists( 'wp_pagenavi' ) ) : ?>
            <?php wp_pagenavi(); ?>
            <?php else : ?>  
                <?php next_posts_link( '<span class="nav-previous"><span class="meta-nav">&laquo;</span> '. __( 'Older posts', 'dkret') .'</span>' ); ?>
                <?php previous_posts_link('<span class="nav-next">'. __('Newer posts','dkret') .' <span class="meta-nav">&raquo;</span></span>'); ?>
            <?php endif; ?>
        </div>

<?php
}
endif;
?>